﻿using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using Emotiv;

namespace DasherBci
{
    // Maps the TrainedAction and Edk.EE_CognitivAction_t enums onto each other.
    public static class TrainedActionCognitivActionMapping
    {
        private readonly static Dictionary<EdkDll.EE_CognitivAction_t, TrainedAction> _mapping =
            new Dictionary<EdkDll.EE_CognitivAction_t, TrainedAction>
                {
                    {EdkDll.EE_CognitivAction_t.COG_NEUTRAL, TrainedAction.Neutral},
                    {EdkDll.EE_CognitivAction_t.COG_LIFT, TrainedAction.Up},
                    {EdkDll.EE_CognitivAction_t.COG_DROP, TrainedAction.Down},
                };

        public static TrainedAction GetTrainedAction(EdkDll.EE_CognitivAction_t cognitivAction)
        {
            if (!_mapping.ContainsKey(cognitivAction)) return TrainedAction.Unset;
            return _mapping[cognitivAction];
        }

        public static EdkDll.EE_CognitivAction_t GetCognitivAction(TrainedAction trainedAction)
        {
            Debug.Assert(trainedAction != TrainedAction.Unset);
            return _mapping.FirstOrDefault(pair => pair.Value == trainedAction).Key;
        }
    }
}
